package com.kodin.polyfit;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;

/**
 * 返回模拟结果
 * best里存储 系数  从低到高
 * 打印模拟过程信息
 */
public class Result {
    private double[][] toArray, src;
    private double[] best;// 多项式系数 a + bx + cx^2 +dx^3
    private String toString;

    public double[][] getToArray() {
        return toArray;
    }

    /**
     * 带入x使用best系数求解y
     *
     * @param x
     * @return
     */
    public double calculateY(double x) {
        double y = 0;
        for (int j = 0; j < best.length; j++) {
            y += best[j] * Math.pow(x, j);// y = a + bx + cx^2
        }
        return y;
    }

    public void setToArray(double[][] toArray) {
        this.toArray = toArray;
    }

    public double[][] getSrc() {
        return src;
    }

    public void setSrc(double[][] src) {
        this.src = src;
    }

    public Result(double[][] src, double[][] toArray, String toString, double[] best) {
        this.best = best;
        this.src = src;
        this.toArray = toArray;
        this.toString = toString;
    }

    public String toString() {
        String log = "";
        for (int i = 0; i < src.length; i++) {
            log += GsonUtils.toJson(src[i]);
            log += GsonUtils.toJson(toArray[i]);
        }
//        LogUtils.e(log);
        return "Result{" +
                ", toString='" + toString + '\'' +
                '}';
    }
}
